import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
    mode: 'history',
    routes: [{
            path: '/login',
            name: 'Login',
            component: () =>
                import ('@/views/login'),
            meta: {
                isPublic: true
            }
        }, {
            path: '/',
            name: 'main',
            component: () =>
                import ('@/layout/index'),
            children: [{
                    path: '/categories/create',
                    name: 'categoryEdit',
                    component: () =>
                        import ('@/views/categoryEdit')
                },
                {
                    path: '/categories/create/:id',
                    name: 'categoryEdit2',
                    component: () =>
                        import ('@/views/categoryEdit'),
                    props: true
                },
                {
                    path: '/categories/list',
                    name: 'categoryList',
                    component: () =>
                        import ('@/views/categoryList')
                },
                {
                    path: '/goods/create',
                    name: 'goodsEdit',
                    component: () =>
                        import ('@/views/goodsEdit')
                },
                {
                    path: '/goods/create/:id',
                    name: 'goodsEdit2',
                    component: () =>
                        import ('@/views/goodsEdit'),
                    props: true
                },
                {
                    path: '/goods/list',
                    name: 'goodsList',
                    component: () =>
                        import ('@/views/goodsList')
                },
                {
                    path: '/active/step',
                    name: 'activeStep',
                    component: () =>
                        import ('@/views/step')
                },
                {
                    path: '/heroes/create',
                    name: 'heroesEdit',
                    component: () =>
                        import ('@/views/heroesEdit')
                },
                {
                    path: '/heroes/create/:id',
                    name: 'heroesEdit2',
                    component: () =>
                        import ('@/views/heroesEdit'),
                    props: true
                },
                {
                    path: '/heroes/list',
                    name: 'heroesList',
                    component: () =>
                        import ('@/views/heroesList')
                },
                {
                    path: '/articles/create',
                    name: 'articlesEdit',
                    component: () =>
                        import ('@/views/articleEdit')
                },
                {
                    path: '/articles/create/:id',
                    name: 'articlesEdit2',
                    component: () =>
                        import ('@/views/articleEdit'),
                    props: true
                },
                {
                    path: '/articles/list',
                    name: 'articlesList',
                    component: () =>
                        import ('@/views/articleList')
                },
                {
                    path: '/ads/create',
                    name: 'adsEdit',
                    component: () =>
                        import ('@/views/adEdit')
                },
                {
                    path: '/ads/create/:id',
                    name: 'adsEdit2',
                    component: () =>
                        import ('@/views/adEdit'),
                    props: true
                },
                {
                    path: '/ads/list',
                    name: 'adsList',
                    component: () =>
                        import ('@/views/adList')
                },
                {
                    path: '/adminUsers/create',
                    name: 'adminUsersEdit',
                    component: () =>
                        import ('@/views/adminUsersEdit')
                },
                {
                    path: '/adminUsers/create/:id',
                    name: 'adminUsersEdit2',
                    component: () =>
                        import ('@/views/adminUsersEdit'),
                    props: true
                },
                {
                    path: '/adminUsers/list',
                    name: 'adminUsersList',
                    component: () =>
                        import ('@/views/adminUsersList')
                },
            ]
        },

    ]
})

router.beforeEach((to, from, next) => {
    if (!to.meta.isPublic && !localStorage.token) {
        next('/login')
    }
    next()
})
export default router